package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.annotation.OptLogCache;
import com.wcs.exam.common.base.page.Page;
import com.wcs.exam.controller.admin.biz.AdminSysConfigBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.AdminSysConfigListResp;
import com.wcs.exam.controller.admin.resp.AdminSysConfigPageResp;
import com.wcs.exam.controller.admin.resp.AdminSysConfigViewResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Admin-系统配置
 *
 * @author wcs
 * @since 2024-07-06
 */
@Tag(name = "Admin-系统配置")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/sys/config")
public class AdminSysConfigController {

    @NotNull
    private final AdminSysConfigBiz biz;

    @Operation(summary = "系统配置-列表")
    @GetMapping(value = "/list")
    public Result<List<AdminSysConfigListResp>> list(@ModelAttribute AdminSysConfigListReq req) {
        return biz.list(req);
    }

    @Operation(summary = "系统配置-分页")
    @GetMapping(value = "/page")
    public Result<Page<AdminSysConfigPageResp>> page(@ModelAttribute AdminSysConfigPageReq req) {
        return biz.page(req);
    }

    @Operation(summary = "系统配置-添加")
    @OptLog(value = "系统配置添加")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody @Valid AdminSysConfigSaveReq req) {
        return biz.save(req);
    }

    @Operation(summary = "系统配置-查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLogCache
    @GetMapping(value = "/view")
    public Result<AdminSysConfigViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @Operation(summary = "系统配置-编辑")
    @OptLog(value = "系统配置编辑", isUpdate = true)
    @PutMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AdminSysConfigEditReq req) {
        return biz.edit(req);
    }

    @Operation(summary = "系统配置-排序")
    @OptLog(value = "系统配置排序")
    @PutMapping(value = "/sort")
    public Result<String> sort(@RequestBody @Valid List<AdminSysConfigSortReq> reqs) {
        return biz.sort(reqs);
    }

    @Operation(summary = "系统配置-删除")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLog(value = "系统配置删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }
}
